<template>
  <div>
    <h3>entity配置</h3>
    <el-row :gutter="20">
      <el-col :span="4">
        包名：
        <el-input class="input-packkage" placeholder="entity包名" v-model="entitySetting.entityPackage"/>
      </el-col>
      <el-col :span="3" class="col-primary-key-name">
        主键名：
        <el-input placeholder="主键名" class="primary-key-name" v-model="entitySetting.primaryKeyName"/>
      </el-col>
      <el-col :span="6" class="col-primary-key-type">
        主键类型：
        <el-input placeholder="主键类型" class="primary-key-type" v-model="entitySetting.primaryKeyType"/>
      </el-col>
      <el-col :span="6" class="col-strategy">
        主键策略：
        <el-select :disabled="projectSetting.ormType===1" placeholder="请选择主键策略" v-model="entitySetting.strategy">
          <el-option value="0" label="默认策略"></el-option>
          <el-option value="31" label="TABLE" v-show="projectSetting.ormType===2"></el-option>
          <el-option value="32" label="SEQUENCE" v-show="projectSetting.ormType===2"></el-option>
          <el-option value="33" label="IDENTITY" v-show="projectSetting.ormType===2"></el-option>
          <el-option value="34" label="AUTO" v-show="projectSetting.ormType===2"></el-option>
          <el-option value="20" label="AUTO" v-show="projectSetting.ormType===3"></el-option>
          <el-option value="21" label="INPUT" v-show="projectSetting.ormType===3"></el-option>
          <el-option value="22" label="ID_WORKER" v-show="projectSetting.ormType===3"></el-option>
          <el-option value="23" label="UUID" v-show="projectSetting.ormType===3"></el-option>
          <el-option value="24" label="NONE" v-show="projectSetting.ormType===3"></el-option>
          <el-option value="25" label="ID_WORKER_STR" v-show="projectSetting.ormType===3"></el-option>
        </el-select>
      </el-col>
      <el-col :span="5">
        父类：
        <el-input placeholder="父类全类名" class="base-class-full-name" v-model="entitySetting.baseClassFullName"/>
      </el-col>
    </el-row>

    <el-row :gutter="20">
      <el-col :span="11">
        <el-col :span="6">
          <el-checkbox label="equal和hash" v-model="entitySetting.equalAndHash"/>
        </el-col>
        <el-col :span="6">
          <el-checkbox label="toString" v-model="entitySetting.m2String"/>
        </el-col>
        <el-col :span="6">
          <el-checkbox label="无参构造" v-model="entitySetting.noArgConstructor"/>
        </el-col>
        <el-col :span="6">
          <el-checkbox label="链式调用" v-model="entitySetting.chain"/>
        </el-col>
      </el-col>
      <el-col :span="3">
        <el-button type="info" plain @click="mappingModalShow" :disabled="!tableHasSelected">类型映射
        </el-button>
      </el-col>
      <!--<el-col :span="3">
        类名后缀:
        <el-input placeholder="类名后缀" :disabled="!tableHasSelected"/>
      </el-col>-->
      <el-col :span="5">
        排除字段：
        <el-input placeholder="多个用,分隔" class="exclude-column" v-model="entitySetting.excludeColumns"/>
      </el-col>
      <el-col :span="5">
        类名后缀：
        <el-input placeholder="类名后缀" class="class-sufix" v-model="entitySetting.classSufix"/>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import {mapGetters} from "vuex";
  import {mapState} from "vuex";

  export default {
    name: "Project",
    computed: {
      ...mapGetters(["entitySetting", "tableHasSelected"]),
      ...mapState(["linkIsOpen", "currentLinkInfo", "projectSetting"]),
      singleTableMappingModalShow: {
        set(flag) {
          this.$store.dispatch("singleTableMappingModalShow", flag);
        }, get() {
          return this.$store.getters.singleTableMappingModalShow;
        }
      }
    }, methods: {
      mappingModalShow() {
        let count = 0;
        let database = "";
        let table = "";
        let currentLinkInfoDatabases = this.currentLinkInfo.databases;
        console.log(JSON.stringify(currentLinkInfoDatabases));
        currentLinkInfoDatabases.forEach(d => {
          d.tables.forEach(t => {
            if (t.checked) {
              count++;
              table = t.name;
              database = d.name;
            }
          });
        });

        if (count !== 1) {
          this.$store.dispatch("mappingModalShow", true);
        } else {
          let tableInfo = {
            table: table,
            database: database
          };
          this.$store.dispatch("loadSingleTableMapping", tableInfo);
          this.$store.dispatch("singleTableMappingModalShow", true);
        }
      }
    }, watch: {
      projectSetting: {
        deep: true, //深度监视
        handler: function (newValue, oldValue) {
          if (newValue.ormType === 2) {
            this.entitySetting.strategy = "20";
          }
          if (newValue.ormType === 3) {
            this.entitySetting.strategy = "33";
          }
        }
      }
    }
  }

</script>

<style scoped>
  @import "../../../static/css/content.css";

  .el-select, .el-option {
    width: 63%;
  }

  .col-strategy {
    padding-left: 0;
  }

  .el-input {
    width: 43%;
  }

  .input-package {
    width: 63%;
  }

  .base-class-full-name {
    width: 70%;
  }

  .exclude-column {
    width: 58%;
  }

  .col-primary-key-type {
    width: 22%;
  }

  .primary-key-type {
    width: 58%;
  }

  .el-col {
    padding-right: 0 !important;
  }

  .col-primary-key-name {
    width: 14%;
  }

  .primary-key-name {
    width: 45%;
  }

  .class-sufix {
    width: 48%;
  }

  .primary-key-name .el-input__inner {
    padding: 0 0 !important;
  }
</style>
